#ifndef __Math__Play__
#define __Math__Play__

#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include <cocostudio/cocostudio.h>

#include "../../GameConfig.h"
#include "../../GamePlayConfig.h"
#include "../../Data/GameData.h"
USING_NS_CC;
using namespace ui;
using namespace cocostudio;


class PlayManager : public cocos2d::Layer
{
private:
    Size m_screenSize;
    void initBackground();
    void initLayer();
    void initGhost();
    void initGame();
    void initResult();
    void initCongratulations();
    void calculateTimePlay(Ref* pSender);
    
    void ReturnLevelScene();
    void IncreaseGhost(Ref* pSender);
    void DecreaseGhost(Ref* pSender);
    void Clound_Click(Ref* pSender);
    
    Button* m_Cloud;
    LoadingBar* m_loadingBar;
    Button* m_btnIncrease;
    Button* m_btnDecrease;
	Button* m_timePanel;
    Sprite* m_handTutorial;
    Node* m_PlaySelectLayer;
    Node* m_PlayAdjustLayer;
    Node* m_CongratulationsLayer;
    Node* m_ResultLayer;
    Node* m_nodeGhostPlay;
    int m_NumberResult;
    int m_currStar;
    int m_currIndexEquation;
    
	timeline::ActionTimeline* m_timeline;

	//Setting
	Node* m_btnSetting;
	Node* m_pnlSetting;
	bool m_isOpenSetting;
	void setOpenSettingProperty();

    //Audio
    void playStarSound();
    
    void checkVisibleButton();
    void playTutorial();
	void initSetting(Node* nodeRoot);
	void tapSetting(Ref* pSender);
	void tapHelp(Ref* pSender);
	void tapSound(Ref* pSender);
	void tapMusic(Ref* pSender);
    
    std::string m_EquationRoot; // giu lai de update len may
    std::vector<std::string> m_list_EquationResult;
    std::vector<Expression> m_list_EquationRoot;

	virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
public:
    std::vector<EGameStatus> m_list_AnswerStatus;
    std::vector<int> m_list_score;
    std::vector<int> m_list_star;
    static Scene* createScene();
    void update(float dt);
    void initialize();
    void reload();
    void OpenCongratulationsLayer();
    void OpenResultLayer();
    void OpenPlaySelectLayer();
    void OpenPlayAdjustLayer();
    void clearCache();
    static EGameStatus m_EGameStatus; // 0 - normal   1 - win   2 - lose
    static bool m_isTutorial;
    float kScale;
    
    EGameMode m_gameMode;
    EPlayType m_playType;
	int m_time;
	int m_tempTime;
	float m_valueTimeBar;
	
	~PlayManager();
    virtual bool init();
    CREATE_FUNC(PlayManager);
};


#endif // __HELLOWORLD_SCENE_H__
